// pages/my/collect/index.js
import {
  BASE_URL
} from '../../../constant/index'
import {
  getLocalHistory,
  clearHistory
} from '../../../utlis/localHistory'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    BASE_URL,
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getCollectList()
  },
  onShow() {
    this.getCollectList()
  },
  async getCollectList() {
    const list = getLocalHistory()
    this.setData({
      list
    })
  },
  // 跳转动态详情
  gotoDetail(e) {
    console.log(e)
    const docid = e.currentTarget.dataset.docid
    wx.navigateTo({
      url: '../../home/detail/index?docid=' + docid,
    })
  },
  // 清空所有历史
  clearAll(e) {
    let that = this
    wx.showModal({
      title: '提示',
      content: '是否清楚所有历史记录？',
      complete: (res) => {


        if (res.confirm) {
          clearHistory()
          that.getCollectList()
        }
      }
    })
  }
})